package com.woniuxy.controller;

import com.woniuxy.entity.MenuEntity;
import com.woniuxy.entity.MenusRoleDTO;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 马宇航
 * @Do: 菜单用的controller
 * @DateTime: 22/05/25/0025 上午 10:42
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RequestMapping("/rbacMenu")
public class RbacMenuController {
    @Autowired
    RbacMenuService rbacMenuService;
    @GetMapping("/menu")
    public ResponseEntity findAll(){
       return rbacMenuService.findAll();
    }
    @GetMapping("/getFatherMenu")
    public ResponseEntity getFatherMenu(){
        return rbacMenuService.getFatherMenu();
    }
    @PutMapping("/menu")
    public ResponseEntity saveMenu(@RequestBody MenuEntity menuEntity){

        return rbacMenuService.saveMenu(menuEntity);
    }
    @GetMapping("/menu/{roleId}")
    public ResponseEntity findAll(@PathVariable int roleId){
        return rbacMenuService.findAllByRoleId(roleId);
    }

    @PostMapping("/menu")
    public ResponseEntity saveMenusByRoleId(@RequestBody MenusRoleDTO menusRoleDTO){
        return rbacMenuService.saveMenusByRoleId(menusRoleDTO);
    }
    /**
     * 通过当前登录用户的角色id，查询出他所拥有的菜单信息
     * ChangeLog : 1. 创建 (22/05/25/0025 下午 5:27 [马宇航]);
     * @param roleId
     * @return com.woniuxy.entity.ResponseEntity
    */
    @GetMapping("/menuByRoleId/{roleId}")
    public ResponseEntity getMenusByRoleId(@PathVariable int roleId){
        return rbacMenuService.getMenusByRoleId(roleId);
    }
}
